<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        window.onload = function() {


            sock = new WebSocket("ws://localhost:8089/ws");

            sock.onopen = function() {
                console.log("connected to server" );
            }

            sock.onclose = function(e) {
                console.log("connection closed (" + e.code + ")");
            }

            sock.onmessage = function(e) {
                console.log("message received: " + e.data);
            }
        };

        function send() {
            console.log("start")

            var msg = {"username":"root","password":"1234"}
            var jsonStr = JSON.stringify(msg);
            console.log(jsonStr)
            sock.send(jsonStr);
        }
        function heart() {
            var msg = {"mid":20181213,"mtype":200,"time":123456,"date":null}
            var jsonStr = JSON.stringify(msg);
            sock.send(jsonStr);
        }
        function sendHeart() {
            console.log("start")
            window.setInterval("heart()",2000)
        };
    </script>

</head>
<body>
<div id="sse">
    <form>
        <p>
            Message: <input id="message" type="text" value="Hello, world!">
        </p>
    </form>
    <button onclick="send();">Send Message</button>
    <div>
        <p>发送心跳</p>
    </div>
        <button onclick="sendHeart()">Close Message</button>

</div>
</body>
</html>